/*
ID: guoxu1
PROG: milk
LANG: C++
*/
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

struct farmer
{
  int price;
  int amount;
  farmer()
  {
    price = 0;
    amount = 0;
  }

  bool operator< ( const farmer& f ) const
  {
    return price < f.price;
  }
};

#define cin fin
#define cout fout

int main()
{
  ifstream fin( "milk.in" );
  ofstream fout( "milk.out" );
  int amount = 0, n = 0;
  cin >> amount >> n;
  vector<farmer> farmers( n );
  for( int i = 0; i < n; i++ )
  {
    cin >> farmers[i].price >> farmers[i].amount;    
  }
  std::sort( farmers.begin(), farmers.end() );
  int total = 0;

  for( size_t i = 0; i < farmers.size() && amount > 0; i++ )
  {
    int am = min( farmers[i].amount, amount );
    amount -= am;
    total += farmers[i].price * am;
  }

  cout << total << endl;
}

